package com.hk.core.elasticsearch.query;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.data.elasticsearch.core.query.Criteria;

/**
 * @author Kevin
 * @date 2022-11-28 09:20
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public abstract class Conditions {

    public static Criteria eq(boolean matcher, String field, Object value) {
        return matcher ? Criteria.where(field).is(value) : null;
    }

    public static Criteria eq(String field, Object value) {
        return eq(true, field, value);
    }

    public static Criteria expression(String field, String value) {
        return Criteria.where(field).expression(value);
    }

    public static Criteria fuzzy(String field, String value) {
        return Criteria.where(field).fuzzy(value);
    }

    public static Criteria contains(String field, String value) {
        return Criteria.where(field).contains(value);
    }

    public static Criteria startsWith(String field, String value) {
        return Criteria.where(field).startsWith(value);
    }

    public static Criteria endsWith(String field, String value) {
        return Criteria.where(field).endsWith(value);
    }

    public static Criteria greaterThan(String field, Object value) {
        return Criteria.where(field).greaterThan(value);
    }

    public static Criteria greaterThanEqual(String field, Object value) {
        return Criteria.where(field).greaterThanEqual(value);
    }

    public static Criteria lessThan(String field, Object value) {
        return Criteria.where(field).lessThan(value);
    }

    public static Criteria lessThanEqual(String field, Object value) {
        return Criteria.where(field).lessThanEqual(value);
    }

    public static Criteria in(String field, Iterable<?> values) {
        return Criteria.where(field).in(values);
    }

    public static Criteria in(String field, Object[] values) {
        return Criteria.where(field).in(values);
    }

    public static Criteria notIn(String field, Iterable<?> values) {
        return Criteria.where(field).not().in(values);
    }

    public static Criteria notIn(String field, Object[] values) {
        return Criteria.where(field).not().in(values);
    }

    public static Criteria between(String field, Object start, Object end) {
        return Criteria.where(field).between(start, end);
    }

    public static Criteria within(String field, String geoLocation, String distance) {
        return Criteria.where(field).within(geoLocation, distance);
    }

    public static Criteria or(Criteria criteria) {
        return Criteria.or().or(criteria);
    }

}
